package com.example.baiduai.factory;

import com.baidu.aip.face.AipFace;
import com.baidu.aip.imageclassify.AipImageClassify;
import com.baidu.aip.nlp.AipNlp;
import com.baidu.aip.speech.AipSpeech;
import com.example.baiduai.Common;

/**
 * @author wangyizhu
 * @version "1.8.0_131"
 * @email 2641956765@qq.com
 * @desc: 该类是一个工厂类，只负责创建不同的对象
 * 创建对象时采用单例模式
 * @Time 2022/09/19 17:30
 */
public class AipFactory {
    private static AipNlp aipNlp;
    private static AipSpeech aipSpeech;
    private static AipFace aipFace;

    /**
     * 该方法采用单例的形式创建全局对象
     */
    private static AipImageClassify aipImageClassify;

    public synchronized static AipImageClassify getOcrInstance() {
        if (aipImageClassify != null) {
            return aipImageClassify;
        }
        aipImageClassify = new AipImageClassify(Common.APP_ID, Common.API_KEY, Common.SECRET_KEY);
        return aipImageClassify;
    }

    /**
     * @return
     */
    public synchronized static AipFace getAipFace() {
        if (aipFace != null) {
            return aipFace;
        }
        aipFace = new AipFace(Common.APP_ID, Common.API_KEY, Common.SECRET_KEY);
        return aipFace;
    }

    public static AipNlp getNLPInstance() {
        if (aipNlp != null) {
            return aipNlp;
        }
        aipNlp = new AipNlp(Common.APP_ID, Common.API_KEY, Common.SECRET_KEY);
        return aipNlp;
    }

    /**
     * 该方法以单例模式创建aipSpeech对象全局使用
     *
     * @return
     */
    public static AipSpeech getAipSpeechInstance() {
        if (aipSpeech != null) {
            return aipSpeech;
        }
        aipSpeech = new AipSpeech(Common.APP_ID, Common.API_KEY, Common.SECRET_KEY);
        return aipSpeech;
    }

}
